<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .container {
        display: flex;
        height: 200px;
      }
      .box1 {
        background-color: pink;
        /* width: 187.5px; */
        width: 50rem;
        height: 100%;
      }
      .box2 {
        background-color: deeppink;
        width: 50rem;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box1"></div>
      <div class="box2"></div>
    </div>

    <script>
      /*
        设计稿：iphone6/7/8  375px, 请问 100px 大小的元素转为多少 rem?
          1rem = 3.75px
          xrem = 100px
          x = 100 / 3.75
      */
      setRem();
      function setRem() {
        const clientWidth = document.documentElement.clientWidth;
        const rem = clientWidth / 100;
        document.documentElement.style.fontSize = rem + "px";
      }
      // 监听窗口调整事件
      window.onresize = setRem;
    </script>
  </body>
</html>
